<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>文章列表--layui后台管理模板 2.0</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../css/public.css" media="all" />
	</head>

	<body class="childrenBody">
		<blockquote class="layui-elem-quote">
			当前只支持支付宝、网银转账。<font color="red" size="2">[请勿使用微信支付]</font>
		</blockquote>
		<form class="layui-form">
			<input id="user_name" type="hidden" name="user_name" />
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">账户类型</label>
				<div class="layui-input-block count_type">
					<input type="radio" id="count_type" name="count_type" lay-verify="count_type" value="支付宝" title="支付宝">
					<input type="radio" id="count_type" name="count_type" lay-verify="count_type" value="网银" title="网银">
				</div>
			</div>
			
			<!--支付宝-->
			<div class="zhifubao" style="display:none">
				<div class="layui-form-item layui-row layui-col-xs12">
					<label class="layui-form-label">支付宝账号</label>
					<div class="layui-input-block">
						<input type="text" name="count_Alipay_num" class="layui-input count_Alipay_num" lay-verify="count_Alipay_num" placeholder="请输入支付宝账号">
					</div>
				</div>
				<div class="layui-form-item layui-row layui-col-xs12">
					<label class="layui-form-label">支付宝昵称</label>
					<div class="layui-input-block">
						<input type="text" name="count_Alipay_nickname" class="layui-input count_Alipay_nickname" lay-verify="count_Alipay_nickname" placeholder="请输入支付宝昵称">
					</div>
				</div>
			</div>
			
			<!--网银-->
			<div class="wangyin" style="display: none;">
				<div class="layui-form-item layui-row layui-col-xs12">
					<label class="layui-form-label">银行卡账号</label>
					<div class="layui-input-block">
						<input type="text" name="count_bank_num" class="layui-input count_bank_num" lay-verify="count_bank_num" placeholder="请输入账户账号">
					</div>
				</div>
				<div class="layui-form-item layui-row layui-col-xs12">
					<label class="layui-form-label">所属银行</label>
					<div class="layui-input-block">
						<input type="text" name="count_bank_name" class="layui-input count_bank_name layui-disabled" lay-verify="count_bank_name" placeholder="输入卡号获取所属银行">
					</div>
				</div>
			</div>
			
			<div class="layui-form-item layui-row layui-col-xs12">
				<div class="layui-input-block">
					<button id="addcount" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="addcount">立即添加</button>
					<button type="reset" class="layui-btn layui-btn-sm layui-btn-primary">取消</button>
				</div>
			</div>
		</form>
		<script type="text/javascript" src="../../layui/layui.js"></script>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="renwuAdd1.js"></script>
		<script type="text/javascript">
			layui.use(['form', 'layer', 'laydate', 'table', 'laytpl'], function() {
				var form = layui.form,
					layer = parent.layer === undefined ? layui.layer : top.layer,
					$ = layui.jquery,
					laydate = layui.laydate,
					laytpl = layui.laytpl,
					table = layui.table,
					laypage = layui.laypage;
					//$("#shili").show();
					$("#user_name").val(localStorage.login_name);
				var selectwangwang 	= "";
				var good_wangwang	= "";
				
				//获取银行卡判断银行所属银行
				$(".count_bank_num").blur(function(){
					var card = $(".count_bank_num").val();
					$.ajax({
						type:"get",
						url:"https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo="+card+"&cardBinCheck=true",
						dataType:"json",
						success:function(data){
							console.log(data);
							if(data.messages.length){
								layer.msg("您输入的卡号有误，请重新输入");
								$(".count_bank_num").focus();
							}else{
								var bank = data.bank;
								$.ajax({
									type:"get",
									url:"/json/bank.json",
									datatype:"json",
									success:function(obj){
										$(".count_bank_name").val(obj[bank]);
									}
								});
							}
							
						}
					});
				});
				
				//判断用户选择的账户类型=》支付宝|网银
				form.on('radio',function(data){
					console.log(data.value);
					if (data.value==="支付宝") {
						$(".zhifubao").show();
						form.verify({
							count_Alipay_num:function(value){
								if(!value){
									return "支付宝账号不能为空";
								}
							},
							count_Alipay_nickname:function(value){
								if(!value){
									return "支付宝昵称不能为空";
								}
							}
						})
						$(".wangyin").hide();
					} else{
						$(".wangyin").show();
						form.verify({
							
							count_bank_num:function(value){
								if(!value){
									return "请输入银行卡账号";
								}
							},
							count_bank_name:function(value){
								if(!value){
									return "未获取到您的银行卡信息";
								}
							}
						})
						$(".zhifubao").hide();
					}
				});
				form.on("submit(addcount)",function(data){
			        //弹出loading
			        //alert($("#file").val());
			        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
			        var action 	= data.form.action;//表单提交URL地址
			        //var da		= data.field;
			        console.log($(".count_type").val());
			        $.post("http://127.0.0.1:88/index.php/count/count/addCount",data.field,function(obj){
			        	if(obj.code==500){
			        		setTimeout(function(){
				        		layer.msg(obj.msg);
				        	},2000);
			        	}else{
				        	setTimeout(function(){
				        		layer.msg(obj.msg);
				        		top.layer.close(index);
						        //top.layer.msg("商铺添加成功！");
						        layer.closeAll("iframe");
						        //刷新父页面
						        parent.location.reload();
				        		
				        	},2000);
			        	}
			        });
			      /*  setTimeout(function(){
			            top.layer.close(index);
			            //top.layer.msg("商铺添加成功！");
			            layer.closeAll("iframe");
			            //刷新父页面
			            parent.location.reload();
			        },2000);*/
			        return false;
			    })
				
			})
			
		</script>
	</body>

</html>